package com.zhaopin.ranker;

import java.io.File;
import java.util.*;

public class RankerTest {

    public static Object eval(List<Map<String, Object>> results, Map<String, Object> input) {
        List cvs = new ArrayList();
        for (int i = 0; i < results.size(); i++) {
            Object obj = results.get(i);
            cvs.add(obj);
        }

        //1、新逻辑开发
        // P = F * e(-time)
        // 计算F的值
        int a1 = 1;
        int a2 = 1;
        int a3 = 1;
        int b = 1;
        int c = 2;
        int d = 0;
        int k1 = 1;
        int k2 = 2;
        int k3 = 1;


        for (Map<String, Object> result : results) {
            //行业
            Object jdIndustryLevel2Code = result.get("jd_industry_level2_code");
            Object cvIndustryCodeLast = input.get("cv_industry_code_last");
            float eiF = 0f;
            if (jdIndustryLevel2Code.equals(cvIndustryCodeLast)) {
                //min{ JD和CV匹配 行业关键词数量 n * k1，10} TODO 此处的n如何计算
                eiF = eiF + a1 * (Math.min(1 * k1, 10));

            }

            //技能
            Object jdSkillRequirement = result.get("jd_skill_requirement");
            Object userWorkSkillTag = input.get("user_work_skill_tag");
            if (jdSkillRequirement.equals(userWorkSkillTag)) {
                //A2 = min { JD和CV匹配 技能关键词数量 n * k2, 20}
                eiF = eiF + a2 * (Math.min(1 * k2, 20));
            }

            //公司关键词匹配 好像赞无
//            Object jdSkillRequirement = result.get("jd_skill_requirement");
//            Object userWorkSkillTag = result.get("user_work_skill_tag");

            //学历
            Object userEduLevelUnifiedAdmitFlag = result.get("user_edu_level_unified_admit_flag");
            Object jd_edu_level = input.get("jd_edu_level");
            if (userEduLevelUnifiedAdmitFlag.equals(jd_edu_level)) {
                eiF = eiF + a3 * (10);
            } else {
                eiF = eiF - a3 * (40);
            }

            //工作年限
            if (true) {
                eiF = eiF + c * 20;
            }
            //可以获取 F的值
            result.put("eiF", eiF);
        }

        List<Object> listBefore = new ArrayList<>();
        List<Object> listAfter = new ArrayList<>();
        int n = 20;
        for (Map<String, Object> result : results) {
            if ((Float) result.get("eiF") > 0 && n > 0) {
                result.put("reRankScore",result.get("eiF"));
                listBefore.add(result);
                n--;
            } else {
                listAfter.add(result);
            }
        }

        listBefore =  downLoad(listBefore,input);
//        listBefore = ScoreRanker.descByReRankScore(listBefore);

        listAfter =  downLoad(listAfter,input);
//        listAfter = ScoreRanker.descByReRankScore(listAfter);
        listBefore.addAll(listAfter);

        return listBefore;
    }

    static List downLoad(List list,Map<String, Object> input){
        int cvCounter = 0;
        Iterator<Object> iter = list.iterator();
        while (iter.hasNext()) {
            Object cvObj = iter.next();
            exposure_processor(cvObj, input);
            cvCounter++;
        }
        return list;
    }

    static void exposure_processor(Object cv, Map<String, Object> input) {
//        def exposure_list = input.get("browsedResumeNumbers");
//        if(exposure_list != null){
//            if(exposure_list.contains(cv.id)){
//                cv.reRankScore = cv.reRankScore -0.4f;
//                cv.extend_exposure_label="曝光";
//            }
//        }
    }

    public static void main(String[] args) {

        File file = new File("/Users/zhaopin/IdeaProjects/easyjar/src/main/java/com/zhaopin/ranker/aaa/aaa/RankerTest111111.java");
        System.out.println(file.mkdir());
        System.out.println("------------------------");
        System.out.println(file.mkdirs());

    }
}
